Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight lines #164

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Hazegard
Copy link

This PR adds an option to highlight specific lines.

  • Highlighting is applied with a grey background at 50% opacity to the selected lines.
  • Line numbers are highlighted using chroma.LineHighlight.

Note: The chosen background style (grey with 50% opacity) works well with both light and dark themes according to my tests. However, I am open to implementing a more configurable or alternative background style if needed.

Highlighting Rules

The --highlight-lines option accepts a list of lines or line ranges, following this syntax:

  • Separator: Each line or range is separated by a semicolon (;).
  • Ranges:
    • A range is defined using a hyphen (-) to separate the start and end.
    • Both start and end are required.
    • end must be strictly greater than start.

Here is an example command demonstrating the feature:

freeze -w 80 --soft-wrap config.go --highlight-lines "31-37;43-45;53" --lines 19,55 --show-line-numbers --theme github

image

Note: this PR takes benefits of the soft wrapping PR proposed here: #163

This commit introduces a `SoftWrap` option that adjusts the behavior
of the `Lines` option and `ShowLineNumbers` when used with the `Wrap` option.

- `Lines`:
Currently, when both `Lines` and `Wrap` options are used, the line count
is computed after wrapping occurs. This can lead to discrepancies where
wrapped lines count as multiple lines, causing the final output to exclude
some original input lines.
With the new `SoftWrap` option, wrapped lines will count as a single line,
ensuring that all lines specified in the `Lines` option are correctly included.

- `ShowLineNumbers`:
When `SoftWrap` is enabled, line numbers are not added to wrapped lines.
This preserves the original line numbering, ensuring consistency with the input file.
The highlighting is done by applying a grey background with 50% opacity
to all selected lines.

The parsing of the option is as follows:
    - Each input (lines or line ranges) is separated by ;
    - To provide a range, "-" separates the start and the end of the range.
    - In a range, both start and end are required, and end must be greater than start.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant